﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes
Imports System.ComponentModel
Imports System.Windows.Media.Animation
Imports System.Windows.Threading
Imports System.Threading
Imports System.Timers
Imports Microsoft.Practices.EnterpriseLibrary.Data.Sql
Imports System.Data
Imports System.Data.SqlClient
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Windows.Forms.Integration
Imports SILMConfig

Partial Public Class MainWindow
    Inherits Window
#Region "Variables"
    Private printThread As Thread
    Public Shared printTimer As System.Timers.Timer
    Shared objSqlDatabase As SqlDatabase
    Shared objDatabaseClass As DatabaseClass

    Private refreshTimer As DispatcherTimer
#End Region

    Public Sub New()
        Me.Cursor = System.Windows.Input.Cursors.Wait
        InitializeComponent()
        objSqlDatabase = New SqlDatabase(GlobalClass._ConStr)
        objDatabaseClass = New DatabaseClass(GlobalClass._ConStr)
        Dim interval As Double = Settings.[Default].RefreshInterval
        refreshTimer = New DispatcherTimer()
        AddHandler refreshTimer.Tick, AddressOf OnRefreshData
        ' refreshTimer.Tick += New EventHandler(AddressOf OnRefreshData)
        refreshTimer.Interval = TimeSpan.FromMilliseconds(interval)
        refreshTimer.Start()
        Me.Cursor = System.Windows.Input.Cursors.Arrow
    End Sub

    Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Me.Cursor = System.Windows.Input.Cursors.Wait
        DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
        LoadControls(GlobalClass._PermissionID)
        Me.Cursor = System.Windows.Input.Cursors.Arrow
        Dim host As New WindowsFormsHost()

        
        'Timer1.Interval = 1000
        'Timer1.Start()
        'Main.initializeArcGisEngine()

        ''Dim formContainer As System.Windows.Forms.Form = New System.Windows.Forms.Form()
        'Dim workspace As SILMConfig.Workspace = New SILMConfig.Workspace()
        'workspace.dbConnexion = Settings.Default.ConnectionStr
        'workspace.configPath = Settings.Default.workspacePath
        'workspace.initWorkspace()
        'workspace.mode = 2
        'host.Child = workspace
        '' Add the interop host control to the Grid 
        '' control's collection of child controls. 
        'gridMainArea.Children.Add(host)
    End Sub

    Private Sub OnRefreshData(ByVal sender As Object, ByVal e As EventArgs)

        Me.Cursor = System.Windows.Input.Cursors.Wait
        'If tablesStatus IsNot Nothing Then
        '    tablesStatus.GetAllTables()
        'End If
        'If cashierOrdersList IsNot Nothing Then
        '    cashierOrdersList.LoadOrders()
        'End If
        'If kitchenOrdersList IsNot Nothing Then
        '    kitchenOrdersList.LoadOrders()
        'End If

        Me.Cursor = System.Windows.Input.Cursors.Arrow
    End Sub

    Private Sub LoadControls(ByVal permissionID As Integer)
        Select Case permissionID
            'Manager
            Case 1
                If True Then
                    'ManagementMenu.Visibility = Visibility.Visible
                    'UsersMenuItem.Visibility = Visibility.Visible
                    'UnitsMenuItem.Visibility = Visibility.Visible
                    'GroupsMenuItem.Visibility = Visibility.Visible
                    'ProductsMenuItem.Visibility = Visibility.Visible
                    'TablesMenuItem.Visibility = Visibility.Visible
                    'OrderMenu.Visibility = Visibility.Visible
                    'NewOrderMenuItem.Visibility = Visibility.Visible
                    'ToolsMenu.Visibility = Visibility.Visible
                    'SettingsMenuItem.Visibility = Visibility.Visible
                    'ChangePasswordMenuItem.Visibility = Visibility.Visible
                    'ReportsMenu.Visibility = Visibility.Visible
                    'SellReportMenuItem.Visibility = Visibility.Visible
                    'ProductPopularityReportMenuItem.Visibility = Visibility.Visible

                    'tablesStatus = New TablesStatusUserControl()
                    'gridSmallArea.Children.Add(tablesStatus)
                    'gridSmallArea.Children(0).SetValue(WidthProperty, gridSmallArea.Width)
                    'gridSmallArea.Children(0).SetValue(HeightProperty, gridSmallArea.Height)

                    'cashierOrdersList = New CashierOrdersListUserControl()
                    'gridMainArea.Children.Add(cashierOrdersList)
                    'gridMainArea.Children(0).SetValue(WidthProperty, gridMainArea.Width)
                    'gridMainArea.Children(0).SetValue(HeightProperty, gridMainArea.Height)
                End If
                Exit Select
                'Cashier
            Case 2
                If True Then
                    'ManagementMenu.Visibility = Visibility.Visible
                    'UsersMenuItem.Visibility = Visibility.Collapsed
                    'UnitsMenuItem.Visibility = Visibility.Visible
                    'GroupsMenuItem.Visibility = Visibility.Visible
                    'ProductsMenuItem.Visibility = Visibility.Visible
                    'TablesMenuItem.Visibility = Visibility.Visible
                    'OrderMenu.Visibility = Visibility.Visible
                    'NewOrderMenuItem.Visibility = Visibility.Visible
                    'ToolsMenu.Visibility = Visibility.Visible
                    'SettingsMenuItem.Visibility = Visibility.Collapsed
                    'ChangePasswordMenuItem.Visibility = Visibility.Visible
                    'ReportsMenu.Visibility = Visibility.Visible
                    'SellReportMenuItem.Visibility = Visibility.Visible
                    'ProductPopularityReportMenuItem.Visibility = Visibility.Visible

                    'tablesStatus = New TablesStatusUserControl()
                    'gridSmallArea.Children.Add(tablesStatus)
                    'gridSmallArea.Children(0).SetValue(WidthProperty, gridSmallArea.Width)
                    'gridSmallArea.Children(0).SetValue(HeightProperty, gridSmallArea.Height)

                    'cashierOrdersList = New CashierOrdersListUserControl()
                    'gridMainArea.Children.Add(cashierOrdersList)
                    'gridMainArea.Children(0).SetValue(WidthProperty, gridMainArea.Width)
                    'gridMainArea.Children(0).SetValue(HeightProperty, gridMainArea.Height)

                End If
                Exit Select
                'Kitchen User
            Case 3
                If True Then
                    'ManagementMenu.Visibility = Visibility.Collapsed
                    'UsersMenuItem.Visibility = Visibility.Collapsed
                    'UnitsMenuItem.Visibility = Visibility.Collapsed
                    'GroupsMenuItem.Visibility = Visibility.Collapsed
                    'ProductsMenuItem.Visibility = Visibility.Collapsed
                    'TablesMenuItem.Visibility = Visibility.Collapsed
                    'OrderMenu.Visibility = Visibility.Collapsed
                    'NewOrderMenuItem.Visibility = Visibility.Collapsed
                    'ToolsMenu.Visibility = Visibility.Visible
                    'SettingsMenuItem.Visibility = Visibility.Collapsed
                    'ChangePasswordMenuItem.Visibility = Visibility.Visible
                    'ReportsMenu.Visibility = Visibility.Collapsed
                    'SellReportMenuItem.Visibility = Visibility.Collapsed
                    'ProductPopularityReportMenuItem.Visibility = Visibility.Collapsed

                    'productAvailability = New ProductAvailabilityUserControl()
                    'gridSmallArea.Children.Add(productAvailability)
                    'gridSmallArea.Children(0).SetValue(WidthProperty, gridSmallArea.Width)
                    'gridSmallArea.Children(0).SetValue(HeightProperty, gridSmallArea.Height)

                    'kitchenOrdersList = New KitchenOrdersListUserControl()
                    'gridMainArea.Children.Add(kitchenOrdersList)
                    'gridMainArea.Children(0).SetValue(WidthProperty, gridSmallArea.Width)
                    'gridMainArea.Children(0).SetValue(HeightProperty, gridSmallArea.Height)

                End If
                Exit Select
            Case Else
                If True Then
                    'Me.DialogResult = False
                End If
                Exit Select
        End Select
    End Sub

    Private Sub UsersMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Try
            Me.Cursor = System.Windows.Input.Cursors.Wait
            DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
            Dim objUsersWindow As New UsersWindow()
            objUsersWindow.Owner = Me
            objUsersWindow.ShowDialog()
            objUsersWindow = Nothing
            DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
            Me.Cursor = System.Windows.Input.Cursors.Arrow
        Catch
            System.Windows.MessageBox.Show(ErrorMessages.[Default].UnhandledException, "Error", MessageBoxButton.OK, MessageBoxImage.[Error])
        End Try
    End Sub

    Private Sub TablesMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'Try
        '    Me.Cursor = System.Windows.Input.Cursors.Wait
        '    DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        '    Dim objTablesWindow As New TablesWindow()
        '    objTablesWindow.Owner = Me
        '    objTablesWindow.ShowDialog()
        '    objTablesWindow = Nothing
        '    DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
        '    Me.Cursor = System.Windows.Input.Cursors.Arrow
        'Catch
        '    MessageBox.Show(ErrorMessages.[Default].UnhandledException, "Error", MessageBoxButton.OK, MessageBoxImage.[Error])
        'End Try
    End Sub

    Private Sub ProductsMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'Try
        '    Dim selectedTab As String = "Products"
        '    Select Case DirectCast(e.Source, MenuItem).Name
        '        Case "UnitsMenuItem"
        '            selectedTab = "Units"
        '            Exit Select
        '        Case "GroupsMenuItem"
        '            selectedTab = "Groups"
        '            Exit Select
        '        Case Else
        '            selectedTab = "Products"
        '            Exit Select
        '    End Select

        '    Me.Cursor = System.Windows.Input.Cursors.Wait
        '    DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        '    Dim objProductWindow As New ProductWindow(selectedTab)
        '    objProductWindow.Owner = Me
        '    objProductWindow.ShowDialog()
        '    objProductWindow = Nothing
        '    DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
        '    Me.Cursor = System.Windows.Input.Cursors.Arrow
        'Catch
        '    MessageBox.Show(ErrorMessages.[Default].UnhandledException, "Error", MessageBoxButton.OK, MessageBoxImage.[Error])
        'End Try
    End Sub

    Private Sub NewOrderMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim objNewOrderWindow As New NewOrderWindow()
        'objNewOrderWindow.Owner = Me
        'Dim dg As System.Nullable(Of Boolean) = objNewOrderWindow.ShowDialog()
        'If dg = True Then
        '    If cashierOrdersList IsNot Nothing Then
        '        cashierOrdersList.LoadOrders()
        '    End If
        '    If kitchenOrdersList IsNot Nothing Then
        '        kitchenOrdersList.LoadOrders()
        '    End If
        'End If
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub ChangePasswordMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Try
            Me.Cursor = System.Windows.Input.Cursors.Wait
            DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
            Dim objChangePasswordWindow As New ChangePasswordWindow()
            objChangePasswordWindow.Owner = Me
            objChangePasswordWindow.ShowDialog()
            objChangePasswordWindow = Nothing
            DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
            Me.Cursor = System.Windows.Input.Cursors.Arrow
        Catch
            System.Windows.MessageBox.Show(ErrorMessages.[Default].UnhandledException, "Error", MessageBoxButton.OK, MessageBoxImage.[Error])
        End Try
    End Sub

    Private Sub SettingsMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        Dim objSettingsWindow As New SettingsWindow()
        objSettingsWindow.Owner = Me
        objSettingsWindow.ShowDialog()
        objSettingsWindow = Nothing
        DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub Dan_Clicked(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        Process.Start("www.daneshmandi.com")
    End Sub

    Private Sub SellReportMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim objSellReportWindow As New SellReportWindow()
        'objSellReportWindow.Owner = Me
        'objSellReportWindow.ShowDialog()
        'objSellReportWindow = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub ProductPopularityReportMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim objProductPopularityReportWindow As New ProductPopularityReportWindow()
        'objProductPopularityReportWindow.Owner = Me
        'objProductPopularityReportWindow.ShowDialog()
        'objProductPopularityReportWindow = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub AboutMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        Dim objAboutWindow As New AboutWindow()
        objAboutWindow.Owner = Me
        objAboutWindow.ShowDialog()
        objAboutWindow = Nothing
        DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub InventaireMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'Dim interfaceSite As New Site
        'interfaceSite.Visible = True

    End Sub

    Private Sub StatutsMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

    End Sub

    Private Sub FloreInventaireMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interFloFauSys As New FloFauNouv()
        'interFloFauSys.ShowDialog()
        'interFloFauSys = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub
    Private Sub FlorePatrimonialeMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interFloFauSysEndRar As New FloFauEndRar()
        'interFloFauSysEndRar.ShowDialog()
        'interFloFauSysEndRar = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub FauneInventaireMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interFloFauSys As New FloFauNouv()
        'interFloFauSys.ShowDialog()
        'interFloFauSys = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub
    Private Sub FaunePatrimonialeMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interFloFauSysEndRar As New FloFauEndRar()
        'interFloFauSysEndRar.ShowDialog()
        'interFloFauSysEndRar = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub PhénologieMigrateursMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interSttPhenTyp As New SttPhenTyp()
        'interSttPhenTyp.ShowDialog()
        'interSttPhenTyp = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub
    Private Sub MicroorganismesInventaireMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interFloFauSys As New FloFauNouv()
        'interFloFauSys.ShowDialog()
        'interFloFauSys = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub
    Private Sub FormesPatrimonialeMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interFloFauSysEndRar As New FloFauEndRar()
        'interFloFauSysEndRar.ShowDialog()
        'interFloFauSysEndRar = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub
    Private Sub TypologiesInventaireMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        '    DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        '    Dim interVegetnTyp As New VegetnTyp
        '    interVegetnTyp.ShowDialog()
        '    interVegetnTyp = Nothing
        '    DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
        'End Sub
    End Sub
    Private Sub FormationsPatrimonialeMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interVegetnTypEndRar As New VegetnTypEndRar()
        'interVegetnTypEndRar.ShowDialog()
        'interVegetnTypEndRar = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub HabitatsInventaireMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interHabitatsTyp As New HabitatsTyp()
        'interHabitatsTyp.ShowDialog()
        'interHabitatsTyp = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub
    Private Sub HabitatsPatrimonialeMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interHabitTypEndRar As New HabitTypEndRar()
        'interHabitTypEndRar.ShowDialog()
        'interHabitTypEndRar = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub RelevésMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interFloFauRel As New FloFauRel()
        'interFloFauRel.ShowDialog()
        'interFloFauRel = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub ReglementationMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interRglttn As New Rglttn()
        'interRglttn.ShowDialog()
        'interRglttn = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

    Private Sub ActeursMenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        'DirectCast(Me.Resources("StoryboardFadeOut"), Storyboard).Begin(Me)
        'Dim interConcernTyp As New ConcernTyp()
        'interConcernTyp.ShowDialog()
        'interConcernTyp = Nothing
        'DirectCast(Me.Resources("StoryboardFadeIn"), Storyboard).Begin(Me)
    End Sub

End Class

